package com.example.rss_reder;


import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;
import android.widget.TextView;

public class SubActivity extends Activity {
	SubAdapter adapter;
	ArrayList<WeatherList> data;
	private final int DID = 0;
	private final int WHAT = 0;
	String url = null;
	ListView lv;
	
	Handler handler = new Handler(){
		public void handleMessage(Message msg){
			switch (msg.what){
				case WHAT:
					lv = (ListView)findViewById(R.id.lv_sub);
					lv.setAdapter(adapter);
					
					removeDialog(DID);
					break;
			}
		}
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.sub_main);
		
		Intent i = getIntent();
		
		url = i.getExtras().getString("url");
		
		TextView t = (TextView)findViewById(R.id.tv_p);
		
		t.setText(i.getExtras().getString("place"));
		
		callList();

	}
	

	void callList(){
		showDialog(DID);
		
		Thread thread = new Thread(){
			public void run(){
				data = new ArrayList<WeatherList>();
				MyParsing p = new MyParsing(url);
				data = p.getData();
				
				adapter = new SubAdapter(SubActivity.this, data); 
			
				Message msg = handler.obtainMessage(WHAT);
				handler.sendMessage(msg);

			};
		};
		
		thread.start();
	
	}

	protected Dialog onCreateDialog(int id){
		ProgressDialog d = new ProgressDialog(this);
		switch(id){
			case DID:
				d.setMessage("Loding...");
				d.setIndeterminate(true);
				d.setCancelable(true);
				return d;
		}
		return d;
	}
	
}
